home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / mkpasswd / mkpasswd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.3 KB  |  79 lines

  1. /* mkpasswd.c: generate encryped/encoed passwd */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/mkpasswd/RCS/mkpasswd.c,v 6.0 1991/12/18 20:31:22 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/mkpasswd/RCS/mkpasswd.c,v 6.0 1991/12/18 20:31:22 jpo Rel $
  9.  *
  10.  * $Log: mkpasswd.c,v $
  11.  * Revision 6.0  1991/12/18  20:31:22  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19.  
  20. #ifdef BSD42
  21. #define RAND random
  22. #define SRAND srandom
  23. #else
  24. #define RAND rand
  25. #define SRAND srand
  26. #endif
  27.  
  28. char    *myname;
  29.  
  30. static void findpass ();
  31.  
  32. main (argc, argv)
  33. int    argc;
  34. char    **argv;
  35. {
  36.     extern char    *optarg;
  37.     extern int    optind;
  38.     int    opt;
  39.     char    *pass;
  40.  
  41.     myname = argv[0];
  42.     while((opt = getopt(argc, argv, "")) != EOF)
  43.         switch (opt) {
  44.             default:
  45.             fprintf (stderr, "Usage: %s", myname);
  46.             break;
  47.         }
  48.     argc -= optind;
  49.     argv += optind;
  50.  
  51.  
  52.     findpass ();
  53.     
  54. }
  55.  
  56. char saltkeys[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";
  57. extern char *crypt ();
  58.  
  59. static void findpass ()
  60. {
  61.     char *pass, *epass;
  62.     char saltc[3];
  63.     time_t now;
  64.  
  65.     (void) time (&now);
  66.     SRAND (now);
  67.  
  68.     saltc[0] = saltkeys[RAND () % ((sizeof saltkeys) - 1)];
  69.     saltc[1] = saltkeys[RAND () % ((sizeof saltkeys) - 1)];
  70.     saltc[2] = 0;
  71.  
  72.     pass = getpassword ("Password: ");
  73.     epass = crypt (pass, saltc);
  74.     
  75.     bzero (pass, strlen (pass));
  76.     
  77.     printf ("%s\n", epass);
  78. }
  79.